home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol06 / 04 / winstdio / wmhandlr.c < prev    next >
C/C++ Source or Header  |  1991-07-01  |  3KB  |  73 lines

  1. /*
  2. WMHANDLR.C
  3. Event (WM_ message) handlers - implementation
  4. Dave Maxey and Andrew Schulman - 1991
  5. */
  6.  
  7. #include <windows.h>
  8. #include "wmhandlr.h"
  9.  
  10. long            defwmhandler(HWND, unsigned, WORD, LONG);
  11.  
  12. WMHANDLER       wmhandler[WM_USER];
  13.  
  14. /* -----------------------------------------------------------------------  */
  15. /* This is our event processor. It is the dispatcher for the handlers set   */
  16. /* using SetHandler. An Application plugs this function into its            */
  17. /* window, sets handlers for messages, and WndProc handles the rest.        */
  18. /* This window procecedure should never need to be changed!                 */
  19. /* -----------------------------------------------------------------------  */
  20. long FAR PASCAL _export WndProc(HWND hWnd, WORD message, 
  21.     WORD wParam, LONG lParam)
  22.     {
  23.     if (message < WM_USER)
  24.         return (*wmhandler[message])(hWnd, message, wParam, lParam);
  25.     else
  26.         return DefWindowProc(hWnd, message, wParam, lParam);
  27.     }
  28.  
  29. /* ---------------------------------------------------------------- */
  30. /* Routines to get and set the message handlers. Setting to NULL    */
  31. /* uninstalls a handler, by setting the handler to the default      */
  32. /* which calls Windows own DefWndProc.                              */
  33. /* ---------------------------------------------------------------- */
  34. WMHANDLER wmhandler_get(unsigned message)
  35.     {
  36.     return (message < WM_USER) ? wmhandler[message] : 0;
  37.     }
  38.  
  39. WMHANDLER wmhandler_set(unsigned message, WMHANDLER f)
  40.     {
  41.     WMHANDLER oldf;
  42.     if (message < WM_USER)
  43.         {
  44.         oldf = wmhandler[message];
  45.         wmhandler[message] = f ? f : defwmhandler;
  46.         return (oldf ? oldf : defwmhandler);
  47.         }
  48.     else
  49.         return 0;
  50.     }
  51.  
  52. /* ----------------------------------------------------------------------- */
  53. /* This is a default handler so that an application chain on to a previous */
  54. /* handler from their current one without having to worry what was there   */
  55. /* before. All this default handler does is to call DefWindowProc.         */
  56. /* ----------------------------------------------------------------------- */
  57. long defwmhandler(HWND hwnd, unsigned message, WORD wParam, LONG lParam)
  58.     {   
  59.     return DefWindowProc(hwnd, message, wParam, lParam);
  60.     }
  61.  
  62. /* -------------------------------------------------------------------  */
  63. /* MUST BE CALLED BEFORE THE APPLICATION WINDOW IS CREATED -            */
  64. /* Just inits the array of handlers to the default..                    */
  65. /* -------------------------------------------------------------------  */
  66. void wmhandler_init(void)
  67.     {
  68.     WMHANDLER *pwm;
  69.     int i;
  70.     for (i=0, pwm=wmhandler; i < WM_USER; i++, pwm++) 
  71.         *pwm = defwmhandler;
  72.     }
  73.